$(function(){
	/*获取订单详情*/
	var informHTML="";
	var remindHTML="";
	var orderType="";
	var curState=$('.am-active a').html();
	var cutTab;
	var orderState;
	var orderData=[];
	function getOrders(){
		console.log(typeof curState)
			switch (true){
			case curState == '全部':
				orderType='';
				cutTab=$('.all-order');
			break;
			case curState=='待付款':
				orderType='1';
				cutTab=$('.wait-order');
			break;
			case curState=='已付款':
				orderType='2';
				cutTab=$('.already-order');
			break;
			case curState=='退款':
				orderType='3';
				cutTab=$('.tuikuan-order');
			break;
			case curState=='取消':
				orderType='4';
				cutTab=$('.quxiao-order');
			break;
		    }
		ym.ajax({
        url: "/ymUserInfrom/order",
        param:{
           orderPayState:orderType
        },
        success: function (data) {
        	var newData=data.obj;
        	orderData=data.obj;
        	if(data.res==1){
	        	if(newData.leng!==0||newData[0]!=='null'){
	        		informHTML="";
	        		for (var i = 0; i < newData.length; i++) {
	        			switch (newData[i].orderPayState){
						case '1':
							orderState='待付款';
						break;
						case '2':
							orderState='已付款';
						break;
						case '3':
							orderState='退款';
						break;
						case '4':
							orderState='取消';
						break;
					    }
	        			informHTML+="<div class='content-tab dynamic-tab' curIndex='"+newData[i].orderId+"'>"+
								    "<div class='cart-title'>"+
									"<div class='cart-name'>"+
									"<p class='cart-id'>订单编号："+newData[i].outTradeNo+"</p>"+
									"</div>"+
									"<div style='cart-state'>"+
									"<p class='color85'>"+orderState+"</p>"+
									"</div>"+
								    "</div>"+
								    "<div class='dynamic-tab-desc'>"+
								    "<ul class='am-list cart-list'>"+
								    "<li class='am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left'>"+
								    "<div>"+
								    "<div class='am-u-sm-4 am-list-thumb'>"+
									"<a href='javascript:void(0)'>"+
									"<img src='"+newData[i].attachmentUrl+"' />"+
									"</a>"+
									"</div>"+
									"<div class=' am-u-sm-8 am-list-main am-padding-0'>"+
									"<h3 class='am-list-item-hd'><a href='javascript:void(0)'>"+newData[i].goodsName+"</a></h3>"+
									"<p>创建时间："+newData[i].createTime+"</p>"+
									// "<div class='am-list-item-text'><p>主讲人： <span>"+newData[i].lecturer+"</span> 节数： <span>"+newData[i].totalCost+"</span></p></div>"+
									// "<div class='lesson-price'><p>￥"+newData[i].totalPrice+"元</p></div>"+
									"</div>"+
								    "</div>"+
								    "</li>"+
								    "<li>"+
								    "<div class='order-price'><p>合计：￥"+newData[i].totalCost/100+"元</p></div>"+
								    "</li>"+
								    "<li>"+
								    "<div class='order-do'>"+
								    // "<button class='getXq' curIndex='"+newData[i].outTradeNo+"'>订单详情</button>"+
								    "<button id='delOrder' curIndex='"+newData[i].orderId+"'>删除订单</button>"+
								    "</div>"+
								    "</li>"+
								    "</ul>"+
								    "</div>"+
							        "</div>";
	        		}
	        		cutTab.html(informHTML);
	        	}else{
	        		cutTab.html("<div class='content-tab dynamic-tab am-text-center'><p><img style='height:150px' src='../img/no.jpg'></p></div>");
	        	}
	        }else{
	        	cutTab.html("<div class='content-tab dynamic-tab am-text-center'><p><img style='height:150px' src='../img/no.jpg'></p></div>");
	        }
        }
    	});
	}
	getOrders();
	$('#cartNav li').click(function(){
		curState=$(this).children().html();
		getOrders();
	})
	/*查看订单详情*/
	$('body').on('click','.getXq',function(){
		for (var i = 0; i < orderData.length; i++) {
				console.log(orderData[i].outTradeNo)
				if(orderData[i].outTradeNo===$(this).attr('curIndex')){
					sessionStorage.setItem('curData',JSON.stringify(orderData[i]));
					window.location.href='../html/orderXq.html';
			}
		}
	})
	/*查看订单详情*/
	
	$('body').on('click','#delOrder',function(){
				var curIndex=$(this).attr('curIndex');
					ym.ajax({
				        url: "/ymUserInfrom/deleteOrder",
				        param:{
				           orderId:curIndex
				        },
				        success: function (data) {
				        	if(data.res==1){
				        		/*成功*/
				        		console.log(data.obj)
				        		getOrders();
				        		if(data.obj=='1'){
				        			
				        			$('#ceng').modal('open');
				        			$('#info-text').html('删除成功');
				        			curState='全部';
				        			window.setTimeout(function(){
				        				$('#ceng').modal('close');
				        				$('#info-text').html();
				        			},1500)
				        		}else if(data.obj=='0'){
				        			$('#ceng').modal('open');
				        			$('#info-text').html('删除失败');
				        			curState='全部';
				        			window.setTimeout(function(){
				        				$('#ceng').modal('close');
				        				$('#info-text').html();
				        			},1500)
				        		}
				        	}else{
				        		/*失败*/
				        		alert('删除失败')
				        	}
				        }
				    });
	})
})